package com.example.jh352160.surfingtv.thematic_details.customView;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.jh352160.surfingtv.R;
import com.example.jh352160.surfingtv.commodity_details.CommodityDetailsPage;

/**
 * Created by jh352160 on 2016/8/2
 */

public class AllCommodityItem extends LinearLayout {

    Context context;
    ImageView commodityImage;
    TextView commodityName, commodityPrice, temp;

    public AllCommodityItem(Context context) {
        super(context);
        this.context = context;
        init();
    }

    public AllCommodityItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        init();
    }

    private void init() {
        LayoutInflater.from(context).inflate(R.layout.item_index_commodity, this);
        commodityImage = (ImageView) findViewById(R.id.commodityImage);
        commodityName = (TextView) findViewById(R.id.commodityName);
        commodityPrice = (TextView) findViewById(R.id.commodityPrice);
        temp = (TextView) findViewById(R.id.commodityTagline);
        temp.setVisibility(GONE);
    }

    public void setItem(String imageUrl, String name, String price) {
        //commodityImage.setImageResource(R.drawable.mypage_favorites_commodity);
        Glide.with(context).load(imageUrl).into(commodityImage);
        commodityName.setText(name);
        commodityPrice.setText(price);
    }

    public void setData(final String from, final String detilUrl, final boolean isLike, final int targetId) {
        this.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, CommodityDetailsPage.class);
                intent.putExtra("from", from);
                intent.putExtra("detilUrl", detilUrl);
                intent.putExtra("isLike", isLike);
                intent.putExtra("targetId", targetId);
                context.startActivity(intent);
            }
        });
    }
}
